ostree-repo.c: Fix file descriptor cleanup
authorOwen W. Taylor <otaylor@fishsoup.net>
Tue, 13 Sep 2016 13:03:53 +0000 (09:03 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 13 Sep 2016 13:19:10 +0000 (13:19 +0000)
0 was used as an "unset" flag for tmp_dir_fd, which is technically
incorrect. For cache_dir_fd, -1 was used as the sentinal but 0
was checked for, resulting in close(-1).

Closes: #507
Approved by: cgwalters

src/libostree/ostree-repo.c

index e4e1ecbf5e97ffbc0263c1d408b8328d59bde132..d4b1f1d6f6dcf3cd4aab016280d958d74fdaac8a 100644 (file)
@@ -516,9 +516,9 @@ ostree_repo_finalize (GObject *object)
   g_free (self->commit_stagedir_name);
   glnx_release_lock_file (&self->commit_stagedir_lock);
   g_clear_object (&self->tmp_dir);
-  if (self->tmp_dir_fd)
+  if (self->tmp_dir_fd != -1)
     (void) close (self->tmp_dir_fd);
-  if (self->cache_dir_fd)
+  if (self->cache_dir_fd != -1)
     (void) close (self->cache_dir_fd);
   if (self->objects_dir_fd != -1)
     (void) close (self->objects_dir_fd);
@@ -702,6 +702,7 @@ ostree_repo_init (OstreeRepo *self)
 
   self->repo_dir_fd = -1;
   self->cache_dir_fd = -1;
+  self->tmp_dir_fd = -1;
   self->commit_stagedir_fd = -1;
   self->objects_dir_fd = -1;
   self->uncompressed_objects_dir_fd = -1;